const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class department extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      department.hasMany(models.Staff, {
        foreignKey: "department_id",
      }); // define association here
    }
  }
  department.init(
    {
      id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },

      department_name: {
        type: DataTypes.STRING,
        allowNull: false,
        // unique: true         不注销会提示64keys error
      },

      department_duty: {
        type: DataTypes.STRING,
        allowNull: false,
      },

      /*
        permission:权限字段
        {
            1:员工管理
            2:客户管理
            3:厂商管理
            4:项目管理
            5:合同管理
            6:财务管理
            7:产品管理
            8:采购管理
            9:工单管理
            10:售后服务管理
            11:问题管理
            
        }
        */
      permission: {
        type: DataTypes.TEXT, //用字符串代表数字数组
      },
    },
    {
      // indexes:[{
      //     unique:true,
      //     fields:['department_name']
      // }],
      createdAt: false,
      updatedAt: false,
      sequelize,
      modelName: "department",
      tableName: "departments",
    }
  );

  return department;
};
